package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.sys.entity.PocketEntity;
import io.renren.modules.sys.service.PocketService;
import io.renren.common.utils.R;



/**
 * 账目表
 *
 * @author Amadeus
 * @email 313300182@qq.com
 * @date 2020-12-03 14:29:21
 */
@RestController
@RequestMapping("sys/pocket")
@Api(tags = "账目")
public class PocketController {
    @Autowired
    private PocketService pocketService;

    /**
     * 列表
     */
    @ApiOperation(value = "账目表list", response = PocketEntity.class)
    @GetMapping("/list")
    @RequiresPermissions("sys:pocket:list")
    public Result list(@RequestParam Map<String, Object> params) {
        return pocketService.getPocketList(params);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{pocketId}")
    @RequiresPermissions("sys:pocket:info")
    public R info(@PathVariable("pocketId") Long pocketId){
		PocketEntity pocket = pocketService.getById(pocketId);

        return R.ok().put("pocket", pocket);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:pocket:save")
    public Result save(@RequestBody PocketEntity pocket) {
        return pocketService.savePocket(pocket);

    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:pocket:update")
    public Result update(@RequestBody PocketEntity pocket) {
        return pocketService.saveOrUpdatePocket(pocket);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:pocket:delete")
    public R delete(@RequestBody Long[] pocketIds) {
        pocketService.removeByIds(Arrays.asList(pocketIds));

        return R.ok();
    }


    /**
     * 返回首页信息
     */
    @GetMapping("/getHomeList")
    public Result getPocketSumList() {
        return pocketService.getPocketSumList();
    }
}
